'''
Created on Jun 25, 2010

@author: oabalbin
'''
from collections import defaultdict, deque
def read_list_genes(inputfile):
    """
    Read panther gene list
    """
    genlist=defaultdict()
    for line in inputfile:        
        line = line.strip('\n')
        fields = line.split('\t')
        #print fields 
        # To skip headers, star reading samples in column 7 of the file
        if fields[0][0] == '#': 
            continue                             
        if fields[0]=='':
            continue
        genlist[fields[1]] = fields[0]
    
    return genlist


def list_of_names(inputfile):
        
        genlist=deque()
        for line in inputfile:        
            line = line.strip('\n')
            fields = line.split('\t')
            #print fields 
            # To skip headers, star reading samples in column 7 of the file
            if fields[0][0] == '#': 
                continue                             
            if fields[0]=='':
                continue
            print fields[0]
            genlist.append(fields[0])
        
        return genlist

        
        

inputfile='/data/projects/pcst/test/proteomics_names'
inputfile2='/data/projects/pcst/test/protein_names'

outfile='/data/projects/pcst/test/proteomics_names_only_inlist'
outfile2 = open(outfile,'w')

dict1 = read_list_genes(open(inputfile))
list1 = list_of_names(open(inputfile2))

for it in list1:
    if it in dict1:
        outfile2.write(it+'\t'+dict1[it]+'\n')
        print it, dict1[it]

        
        
        
        
        
        